Imports ValidationFramework
Imports ValidationFramework.Web.ASP
Imports QSBusinessLayerVB
Imports System

Partial Public Class GridViewMasterDetailsEditForm
  Inherits Page
  ' Methods
  Private Sub CreateValidations()
    If (personDetailsView.CurrentMode = DetailsViewMode.Edit) Then
      Dim row As DetailsViewRow = personDetailsView.Rows.Item(personDetailsView.DataItemIndex)
            Helper.AddValidation(validatorGenerator.GetValidatorGenerator(), New FindControl(AddressOf row.FindControl))
    End If
  End Sub

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    CreateValidations()
  End Sub

  Protected Sub personDetailsView_DataBound(ByVal sender As Object, ByVal e As EventArgs)
    CreateValidations()
  End Sub

  Protected Sub personDetailsView_ItemUpdating(ByVal sender As Object, ByVal e As DetailsViewUpdateEventArgs)
    e.Cancel = Not MyBase.IsValid
  End Sub

  Protected Sub personDetailsViewObjectDataSource_Updated(ByVal sender As Object, ByVal e As ObjectDataSourceStatusEventArgs)
    personGridView.DataBind()
  End Sub

  Protected Sub personGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
    personDetailsView.ChangeMode(DetailsViewMode.ReadOnly)
  End Sub

  Protected Sub personGridView_Sorted(ByVal sender As Object, ByVal e As EventArgs)
    personDetailsView.ChangeMode(DetailsViewMode.ReadOnly)
  End Sub

  Protected Sub validatorGenerator_TargetObjectRequired(ByVal sender As Object, ByVal e As TargetObjectRequiredEventArgs)
    If (editingPerson Is Nothing) Then
      Dim row As DetailsViewRow = personDetailsView.Rows.Item(personDetailsView.DataItemIndex)
      editingPerson = Helper.GetPerson(New FindControl(AddressOf row.FindControl))
    End If
    e.TargetObject = editingPerson
  End Sub


  Private editingPerson As Person
End Class


